var _config = _interopRequireDefault(require("../../../utils/config")), _cardUtil = _interopRequireDefault(require("../../../utils/card-util")), _contactUtil = require("../../../utils/contact-util");

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _toConsumableArray(t) {
    return _arrayWithoutHoles(t) || _iterableToArray(t) || _nonIterableSpread();
}

function _nonIterableSpread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance");
}

function _iterableToArray(t) {
    if (Symbol.iterator in Object(t) || "[object Arguments]" === Object.prototype.toString.call(t)) return Array.from(t);
}

function _arrayWithoutHoles(t) {
    if (Array.isArray(t)) {
        for (var a = 0, e = new Array(t.length); a < t.length; a++) e[a] = t[a];
        return e;
    }
}

var TABS_INDEX = {
    VISITOR: 0,
    CHAT: 1,
    NICHE: 2,
    ANALYZE: 3
}, appData = getApp().globalData;

Page({
    data: {
        TABS_INDEX: TABS_INDEX,
        app: _config.default.WX_APP_NAME,
        activeIndex: -1,
        loads: []
    },
    onLoad: function() {
        this.setCardData(appData.card), this.initEvents();
    },
    initEvents: function() {
        var a = this;
        [ [ "card.change", this.setCardData.bind(this) ], [ "radar.navbar.change", function(t) {
            return a.navbarInit(t);
        } ], [ "update.globalData.remark", function() {
            var t = a.getTabs();
            t[TABS_INDEX.CHAT].init(), t[TABS_INDEX.NICHE].init(), t[TABS_INDEX.VISITOR].onPullDownRefresh();
        }, !1 ] ].forEach(function(t) {
            return a.$addListener.apply(a, _toConsumableArray(t));
        });
    },
    onReady: function() {
        wx.hideShareMenu();
    },
    onShow: function() {
        wx.chatlistUpdate && (wx.chatlistUpdate = !1, wx.showToast({
            title: "群发消息成功",
            duration: 600
        }));
    },
    onPullDownRefresh: function() {
        var t = this.data, a = t.activeIndex, e = t.card;
        e && e.cardid && ((0, _contactUtil.loadContact)(), this.getTabs()[a].onPullDownRefresh());
    },
    onReachBottom: function() {
        var t = this.data, a = t.activeIndex, e = t.card;
        e && e.cardid && this.getTabs()[a].onReachBottom();
    },
    onTabItemTap: function() {
        this.$report("tabbar_radar");
    },
    getTabs: function() {
        var t = {
            init: function() {},
            onPullDownRefresh: function() {},
            onReachBottom: function() {},
            resetTab: function() {}
        };
        return [ this.selectComponent("#visitor") || t, this.selectComponent("#chatlist") || t, this.selectComponent("#niche") || t, this.selectComponent("#analyze") || t ];
    },
    setCardData: function(t) {
        var a = this, e = this.data.card || {}, n = t.isMember && 0 === t.ishigher;
        this.setData({
            card: t,
            isMasses: n
        }, function() {
            e.guid === t.guid && e.isFeeVer === t.isFeeVer || a.navbarInit(t.isGroup ? t.isFeeVer ? TABS_INDEX.VISITOR : TABS_INDEX.CHAT : TABS_INDEX.VISITOR);
        }), t && t.cardid || this.$route("/pages/tabbar/card/card", "tab");
    },
    navbarInit: function() {
        var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : TABS_INDEX.VISITOR;
        this.setData({
            activeIndex: t,
            loads: [ t ]
        });
        var a = this.getTabs()[TABS_INDEX.ANALYZE];
        a && a.resetTab();
    },
    onNavChange: function(t) {
        var a = this, e = t.detail.index, n = this.data.loads, i = {
            activeIndex: e
        };
        n.includes(e) || (n.push(e), i.loads = n), this.setData(i, function() {
            wx.pageScrollTo({
                scrollTop: 0
            }), a.reportAnaly(e), a.handleNavChange(e);
        });
    },
    reportAnaly: function(t) {
        this.$report("tabbar_radar_" + [ "visitor", "chat", "client", "analyze" ][t]);
    },
    handleNavChange: function(t) {
        if (t !== TABS_INDEX.NICHE) {
            var a = this.selectComponent("#niche");
            a && a.nicheReset && a.nicheReset();
        }
    },
    onShareAppMessage: function(t) {
        var a = this.data.card.guid;
        return "card" === t.target.dataset.type ? _cardUtil.default.shareConfig() : {
            title: "高级版试用开放申请中，点击立即申请",
            path: "/pages/radar/detail/detail?guid=".concat(a),
            imageUrl: "https://img.ibos.cn/common/minicard/buy/tryout.png"
        };
    }
});